package com.example.animation

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Composable
fun AnimateDpAsState() {
    var change by remember {
        mutableStateOf(false)
    }

    var flag by remember {
        mutableStateOf(false)
    }

    val buttonSize by animateDpAsState(targetValue = if (change) 36.dp else 24.dp)

    if (buttonSize == 36.dp) {
        change = false
    }

    IconButton(
        onClick = {
            change = true
            flag = !flag
        }
    ) {
        Icon(
            Icons.Filled.Favorite,
            contentDescription = null,
            modifier = Modifier.size(buttonSize),
            tint = if (flag) Color.Red else Color.Gray
        )
    }
}